using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Ent.Web.Helper
{
    public class SettingHelper
    {
        private Dictionary<int, string> _items = new Dictionary<int, string>();
        public SettingHelper(string path, string CollectionName)
        {
            XMLHelper _xml = new XMLHelper(path);
            DataTable dt = _xml.GetChildNodesAsDataTable("//Settings/Collection[@name='" + CollectionName + "']", "Item", new string[] { "id", "name", "selected" });
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    _items.Add(Convert.ToInt32(dt.Rows[i]["id"]), dt.Rows[i]["name"].ToString());
                }
            }
        }
        public int Count
        {
            get { return _items.Count; }
        }
        public Dictionary<int, string>.KeyCollection Keys
        {
            get { return _items.Keys; }
        }
        public string GetValue(int key)
        {
            if (_items.ContainsKey(key))
                return _items[key];
            else
                return "";
        }
        public int GetKey(string value)
        {
            foreach (int key in _items.Keys)
            {
                if (_items[key] == value)
                    return key;
            }
            return -1;
        }
    }
}
